package com.zking.ssm.controller;

import com.zking.ssm.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/user") //作用在类上面，窄化路径
public class UserController {

    @ModelAttribute //用来注解非请求处理方法
    public void init(Model model){
        User user = new User(); //必须实例化对象
        user.setUname("刘德华");
        String[] jobs = new String[]{"程序员","产品经理","测试","运维" };
        String[] sexList = new String[]{"男","女","不详"};
        model.addAttribute("sexList",sexList);
        model.addAttribute("jobs",jobs);
        model.addAttribute("user",user);
        model.addAttribute("username","鸟哥");
    }

    @RequestMapping("toLogin")
    public ModelAndView toLogin(ModelAndView mv){
        mv.setViewName("login");
        return mv;

    }


    @RequestMapping("toReg")
    public ModelAndView toReg(ModelAndView mv){
        mv.setViewName("reg");
        return mv;

    }

    @RequestMapping("/reg")
    public ModelAndView toReg(User user,ModelAndView mv){
        System.out.println(user);
        mv.setViewName("login");
        return mv;

    }

}
